/*
 * @Author: 彭林
 * @Date: 2021-05-13 19:52:36
 * @LastEditTime: 2021-07-01 15:33:40
 * @LastEditors: 彭林
 * @Description:
 * @FilePath: /src/saas-app/app/api/v1/school.go
 */
package v1

import (
	"saas-app/app/define"
	"saas-app/app/model"
	"saas-app/app/service"
	"saas-app/library/response"

	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
)

// 获取学校列表
func GetSchoolList(r *ghttp.Request) {
	user_id := r.GetCtxVar("user_id").Uint()
	result := service.SchoolUserService().GetSchoolList(user_id)
	response.JsonExit(r, 0, "ok", result)
}

// 创建学校
func CreateSchool(r *ghttp.Request) {

	var (
		data        *define.SchoolParams
		schoolParam *model.School
	)

	if err := r.Parse(&data); err != nil {
		response.JsonExit(r, 1, err.Error())
	}

	if err := gconv.Struct(data, &schoolParam); err != nil {
		response.JsonExit(r, 1, err.Error())
	}

	campus_name := r.GetFormString("campus_name")
	userId := r.GetCtxVar("user_id").Uint()

	service.SchoolService().CreateSchool(campus_name, userId, schoolParam)
	response.JsonExit(r, 0, "创建成功", nil)
}
